# try-except-else 案例
"""
try:
  # 尝试执行的代码
except ExceptionType:
  # 当异常发生时执行的代码
else:
  # 没有异常发生时执行的代码
"""


# def calculate_sum(numbers):
#     try:
#         result = sum(numbers)
#         print("The sum is %s" % result)
#     except TypeError:
#         print("Error: Invalid operand types for '+' operation.")
#     else:
#         print("No error occured.")


# # 调用函数并传入参数
# calculate_sum([1, 2, 3])  # 这将正常执行并输出结果
# calculate_sum([1, "2", 3])  # 这将引发 TypeError

a = 1
b = "2"

try:
    res = a + b
    print(res)
except Exception as e:
    if e == "unsupported operand type(s) for +: 'int' and 'str'":
        print("字符串错误了")
    else:
        print("xie dui le")
